<%--
  Created by IntelliJ IDEA.
  User: wj
  Date: 2018-11-08
  Time: 10:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/static/hplus/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/static/hplus/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script>

        //得到查询的参数
        function queryParams (params) {

        };

        $(function () {
            $("#kehutb").bootstrapTable({
                url:'${pageContext.request.contextPath}/info/querySearch',
                //设置每页多少条数据
                pageSize:2,
                pageList:[2,4,8,16],
                height:300,
                pageNumber:1,
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                //启用服务器端分页
                sidePagination:'server',
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        kname:$("#kname").val()
                    };
                    return temp;
                },
                columns:[
                    {
                        field:'kid',
                        title:'编号'
                    },
                    {
                        field:'kname',
                        title:'姓名'
                    },
                    {
                        field:'kming',
                        title:'客户联系人'
                    },

                    {
                        field:'kphone',
                        title:'联系人'
                    },
                    {
                        field:'kaddress',
                        title:'地址'
                    },

                    {
                        title:'操作',
                        formatter:function(value,row,index){
                            return "<button onclick='javascript:del("+row.kid+")'>删除</button>"
                        }
                    },
                ]
            }) ;
        }) ;

     function searcha() {
            //返回表格的 Options。
            var opts = $("#kehutb").bootstrapTable("getOptions") ;
            var limit = opts.pageSize ;
            var offset = (opts.pageNumber-1) * limit;
            var kname = $("#kname").val() ;
            $.post("${pageContext.request.contextPath}/info/querySearch",{'kname':kname,'limit':limit,'offset':offset},function (data) {
                // var mydata = eval("("+data+")") ;
                //重新绑定表格数据
                $("#kehutb").bootstrapTable('load',data) ;
            })
        }


     var kid;

     function del(kids){
         kid=kids;
         $("#sc").modal('show');

     }

     function dodelete(){
         $.post('${pageContext.request.contextPath}/info/shanchu',{kid:kid},function(data){
             if(data>0){
                 $.post("${pageContext.request.contextPath}/info/querySearch",{'kname':kname,'limit':limit,'offset':offset},function (data) {
                     //重新绑定表格数据
                     $("#kehutb").bootstrapTable('load',data) ;
                     $("#sc").modal('hide');
                 })
             }
         })
     }


/*        function tofenpei(id){
            uid = id ;
            uid = id ;
            var a = 0 ;
            var s = "" ;
            // <div class="radio-inline">
            //<input type='radio' value=>
            //  <label>管理员</label>
            //</div>
            //打开一个对话框
            $("#fenpei").modal('show') ;
            //当对话框加载完成后，绑定年有角色
            $("#fenpei").on("shown.bs.modal",function(){
                //
                if (++a ==1){
                    $.post('${pageContext.request.contextPath}/role/query',{"rid":id},function(data){
                        for (var i=0;i<data.length;i++){
                            var r = data[i] ;
                            var id = r.rid ;
                            var rname = r.rname ;
                            var ischecked = r.ischecked ;
                            if (ischecked) {
                                s = s + "<div class='radio-inline'><input  name='js' checked type='radio' value=" + id + "></input><label>" + rname + "</label></div>";
                            }
                            else
                            {
                                s = s + "<div class='radio-inline'><input  name='js'  type='radio' value=" + id + "></input><label>" + rname + "</label></div>";
                            }
                        }
                        $("#juesebody").html(s) ;
                    }) ;
                }

            }) ;

        }*/
/*
        function toadd() {
            $("#modelId").modal("show") ;
        }*/
/*
        var uid ;*/

       /* function dofenpei() {
            alert(rid);
            //1.得到用户的id，角色的id
            var rid = $("input[name='js']:checked").val() ;
            //2.send ajax
            $.post("${pageContext.request.contextPath}/user/doFenPei",{'uid':uid,'rid':rid},function(){
                //关闭对话框,刷新表格
                $("#fenpei").modal('hide') ;
                //   $("#usertb").bootstrapTable('load') ;
            }) ;
        }*/
    </script


</head>
<body>

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">用户列表</h3>
    </div>
    <div class="panel-body">
        <div class="row" style="margin-bottom: 10px">
            <form action="" class="form-inline">
                <div class="col-sm-4">
                    <button class="btn btn-primary">
                        <span class="glyphicon glyphicon-plus"></span>增加
                    </button>
                </div>
                <div class="col-sm-4 col-sm-offset-4 text-right">

                    <input id="kname" type="text" class="form-control">
                    <input onclick="searcha()" type="button" class="btn btn-primary" value="查询">


                </div>
            </form>
        </div>
        <table id="kehutb"></table>
    </div>
</div>

<!---删除模态框-->
<div class="modal fade" id="sc">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="modelTitleId">提示信息</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-12" id="addrole" style="height: 100px">
                        <p>确认删除客户信息吗？</p>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary"onclick="dodelete()">删除</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>
